﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace ThoiTrangT2B
{
    public partial class UCContent : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadListProduct();
            }
        }

        protected void LoadListProduct()
        {
            string sql = "SELECT * FROM dbo.tblT2BMenu WHERE Level = 1";
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
            string category;
            int cID;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                category = dt.Rows[i]["Ten"].ToString();
                cID = Convert.ToInt32(dt.Rows[i]["ID"]);
                string sSql = "SELECT s.Image,d.TenDM AS Hang,s.TenSP,s.ID,s.Gia,(s.Gia - s.Gia*s.KM/100) AS Giacu,s.KM FROM dbo.tblT2BSanPham s " +
                              "INNER JOIN dbo.tblT2BDanhMuc d ON s.ThuongHieuID_DM = d.ID WHERE s.Menu_ID IN (" + MyCommon.GetSubItems(Convert.ToInt32(dt.Rows[i]["ID"].ToString())) + ") ORDER BY s.UpdateDate DESC";
                DataTable data = SqlHelper.ExecuteDataTable(CommandType.Text, sSql);
                UCProductList Lists = (UCProductList)LoadControl("UCProductList.ascx");
                Lists.SetData(category, cID, data);
                ProductListHolder.Controls.Add(Lists);
            }
        }
    }
}